package com.bardsoftware.foronuvolo.data;

import java.util.Date;

import javax.cache.Cache;


import com.bardsoftware.foronuvolo.server.MessageCache;
import com.bardsoftware.foronuvolo.server.WikiMessageFormatter;
import com.google.appengine.api.datastore.Key;
import com.google.gdata.util.common.base.CharEscapers;

public class AnswersViewItem {
    private String userDisplayName;
    private Date creation;
    private String text;
    private static WikiMessageFormatter formatter = new WikiMessageFormatter();

    public AnswersViewItem(Message m, MessageCache<Key,String> messageTextCache) {
        this.userDisplayName = m.getUserDisplayName();
        this.creation = m.getCreation();
        String cachedText = messageTextCache.get(m.getID());
        if (cachedText != null) {
            this.text = cachedText;
        } else {
            WikiMessageFormatter.Result r = formatter.format(CharEscapers.htmlEscaper().escape(m.getText()));
            this.text = r.text;
            messageTextCache.put(m.getID(), r.text);
        }
    }

    public String getUserDisplayName() {
        return userDisplayName;
    }

    public Date getCreation() {
        return creation;
    }

    public String getText() {
        return text;
    }


}
